<?php	
include("../mysql_connect.php");
include("../error/upload.php");
// Get XML
/*	
	$xmlCreate = '
<ShareGroup UserName="rafale@thetigerparty.com" GroupID="" GroupName="Family" Method="Create">
</ShareGroup>';
	$xmlModify = '
<ShareGroup UserName="rafale@thetigerparty.com" GroupID="32" GroupName="Family" Method="Modify" newName="MyFamily">
	<User ID="4" Name="MemberA" Email="a@family.com"/>
	<User ID="5" Name="MemberB" Email="b@family.com"/>
	<User ID="6" Name="MemberCC" Email="c@family.com"/>
	<User ID="7" Name="MemberD" Email="d@family.com"/>
	<User ID="" Name="MemberE" Email="e@family.com"/>
	<User ID="" Name="MemberF" Email="f@family.com"/>
</ShareGroup>';
	$xmlDelete = '
<ShareGroup UserName="rafale@thetigerparty.com" GroupID="32" GroupName="Family" Method="Delete"/>';

	$xml = simplexml_load_string($xmlDelete);
/*/
	$xml = simplexml_load_file('php://input');
//*/
	// Get ShareGroupAttr
	$GroupAttr = array();
	foreach( $xml->attributes( ) as $attr)
	{
		$UserAttr[] = (string)$attr;
	}
	
	// Ger Group ID
	$UserName = $UserAttr[0];
	
	$strSqlCommand = "SELECT idUSER FROM user WHERE Email=\"$UserName\" ";
	
	if (!$result = mysql_query($strSqlCommand))
 	{
	 	echo "<Error Message=\"".mysql_error()."\" Domain=\"GetFilterView\" />";
	 	echo "<Error Message=\"".$strSqlCommand."\" Domain=\"GetFilterView\" />";
		saveError("GetUserGroup", NULL, date("Y-m-d H:i:s"), mysql_error());
		return;
 	}
	$row = @mysql_fetch_array($result);
		$IDs[] = $row['idUSER'];
	
	
	$strSqlCommand = "SELECT GP.idGROUP, GP.Name FROM sharegroup AS GP ,spot_group_users AS SP_G_U WHERE GP.idGROUP = SP_G_U.GROUP_idGROUP AND SP_G_U.USER_idUSER='".$IDs[0]."'";
	
	
	echo "<JoinGroup>";	
	$resultGroup = mysql_query($strSqlCommand);
	if( @mysql_num_rows($resultGroup) > 0 )
	{
		while($rowGroup = @mysql_fetch_array($resultGroup))
		{
			echo '<Group ID="'.$rowGroup['idGROUP'].'" Name="'.$rowGroup['Name'].'" />';
		}
	}
	echo "</JoinGroup>";
?>